﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TodayWhoModel;

namespace TodayWho
{
    public partial class changepassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["userId"] == null)
                {
                    Response.Redirect("error.aspx");
                }
            }
        }
        protected void btnPassword_onClick(object sender, EventArgs e)
        {
            UserModel userModel = new UserModel();
            userModel.Password = txtPassword.Value.Trim();
            userModel.Email = Session["email"].ToString();
            userModel.UserId = Int32.Parse(Session["userId"].ToString());
            if (!userModel.CheckLogin())
            {
                lblMessage.Text = "Sifre degistirilemedi.Suanki sifrenizi yanlis girdiniz..";
                lblMessage.Visible = true;
            }
            else
            {
                userModel.Password = txtNewPassword.Value.Trim();
                if (!userModel.UpdatePassword())
                {
                    lblMessage.Text = "Sifre degistirilemedi..";
                    lblMessage.Visible = true;
                }
                else
                {
                    lblMessage.Text = "Sifreniz basariyla degistirilmistir..";
                    lblMessage.Visible = true;
                }  
            }

        }
    }
}